<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>class RubyXL::WorkbookRoot - rubyXL 3.4.35</title>


  <meta name="keywords" content="ruby,class,RubyXL::WorkbookRoot">


    <meta name="description" content="Documentation for the RubyXL::WorkbookRoot class">





<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
</script>

<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/rdoc.css" rel="stylesheet">



<body id="top" role="document" class="class">
<div id="navigation-toggle" role="button" tabindex="0" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="navigation">
  <span aria-hidden="true">&#9776;</span>
</div>


<nav id="navigation" role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  

  
<div id="parent-class-section" class="nav-section">
  <h3>Ancestors</h3>
  <ul><li>Object</li></ul>
</div>


  
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">


    <li><a class="include" href="RelationshipSupport.html">RubyXL::RelationshipSupport</a></li>


  </ul>
</div>


  

  
  <div class="nav-section">
    <h3>Class Methods</h3>
    <ul class="link-list" role="directory">

      <li ><a href="#method-c-default">default</a></li>

      <li ><a href="#method-c-parse_zip_file">parse_zip_file</a></li>

    </ul>
  </div>



  <div class="nav-section">
    <h3>Instance Methods</h3>
    <ul class="link-list" role="directory">

      <li ><a href="#method-i-related_objects">related_objects</a></li>

      <li ><a href="#method-i-stream">stream</a></li>

      <li ><a href="#method-i-xlsx_path">xlsx_path</a></li>

    </ul>
  </div>



  <footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a></p>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.15.1.</p>
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>
</footer>

</nav>

<main role="main" aria-labelledby="class-RubyXL::WorkbookRoot">
  
  
    <ol role="navigation" aria-label="Breadcrumb navigation" class="breadcrumb">
      
      <li>
        
        <a href="../RubyXL.html">RubyXL</a><span>::</span>
        
      </li>
      
      <li>
        
        <span>WorkbookRoot</span>
        
      </li>
      
    </ol>
  

  <h1 id="class-RubyXL::WorkbookRoot" class="anchor-link class">
    class RubyXL::WorkbookRoot
  </h1>

  <section class="description">
    
  </section>


  <section id="5Buntitled-5D" class="documentation-section anchor-link">







    <section class="attribute-method-details method-section">
      <header>
        <h3>Attributes</h3>
      </header>


      <div id="attribute-i-content_types" class="method-detail anchor-link">
        <div class="method-heading attribute-method-heading">
          <a href="#attribute-i-content_types" title="Link to this attribute">
            <span class="method-name">content_types</span>
            <span class="attribute-access-type">[RW]</span>
          </a>
        </div>

        <div class="method-description">


        

        </div>
      </div>

      <div id="attribute-i-rels_hash" class="method-detail anchor-link">
        <div class="method-heading attribute-method-heading">
          <a href="#attribute-i-rels_hash" title="Link to this attribute">
            <span class="method-name">rels_hash</span>
            <span class="attribute-access-type">[RW]</span>
          </a>
        </div>

        <div class="method-description">


        

        </div>
      </div>

      <div id="attribute-i-source_file_path" class="method-detail anchor-link">
        <div class="method-heading attribute-method-heading">
          <a href="#attribute-i-source_file_path" title="Link to this attribute">
            <span class="method-name">source_file_path</span>
            <span class="attribute-access-type">[RW]</span>
          </a>
        </div>

        <div class="method-description">


        

        </div>
      </div>

    </section>



     <section id="public-class-5Buntitled-5D-method-details" class="method-section anchor-link">
       <header>
         <h3>Public Class Methods</h3>
       </header>


      <div id="method-c-default" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-c-default" title="Link to this method">
                <span class="method-name">default</span>
                <span class="method-args">()</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="default-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/root.rb, line 25</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">default</span>
  <span class="ruby-identifier">obj</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">document_properties</span>    = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">DocumentPropertiesFile</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">core_properties</span>        = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">CorePropertiesFile</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">relationship_container</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">OOXMLRelationshipsFile</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">content_types</span>          = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentTypes</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-identifier">obj</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


      <div id="method-c-parse_zip_file" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-c-parse_zip_file" title="Link to this method">
                <span class="method-name">parse_zip_file</span>
                <span class="method-args">(zip_file)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="parse_zip_file-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/root.rb, line 62</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">parse_zip_file</span>(<span class="ruby-identifier">zip_file</span>)
  <span class="ruby-identifier">root</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-identifier">root</span>.<span class="ruby-identifier">content_types</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentTypes</span>.<span class="ruby-identifier">parse_file</span>(<span class="ruby-identifier">zip_file</span>, <span class="ruby-constant">ContentTypes</span><span class="ruby-operator">::</span><span class="ruby-constant">XLSX_PATH</span>)
  <span class="ruby-identifier">root</span>.<span class="ruby-identifier">load_relationships</span>(<span class="ruby-identifier">zip_file</span>, <span class="ruby-constant">OOXMLTopLevelObject</span><span class="ruby-operator">::</span><span class="ruby-constant">ROOT</span>)

  <span class="ruby-identifier">wb</span> = <span class="ruby-identifier">root</span>.<span class="ruby-identifier">workbook</span>
  <span class="ruby-identifier">wb</span>.<span class="ruby-identifier">root</span> = <span class="ruby-identifier">root</span>

  <span class="ruby-identifier">wb</span>.<span class="ruby-identifier">sheets</span>.<span class="ruby-identifier">each_with_index</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">sheet</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">sheet_obj</span> = <span class="ruby-identifier">wb</span>.<span class="ruby-identifier">relationship_container</span>.<span class="ruby-identifier">related_files</span>[<span class="ruby-identifier">sheet</span>.<span class="ruby-identifier">r_id</span>]

    <span class="ruby-identifier">wb</span>.<span class="ruby-identifier">worksheets</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">sheet_obj</span> <span class="ruby-comment"># Must be done first so the sheet becomes aware of its number</span>
    <span class="ruby-identifier">sheet_obj</span>.<span class="ruby-identifier">workbook</span> = <span class="ruby-identifier">wb</span>

    <span class="ruby-identifier">sheet_obj</span>.<span class="ruby-identifier">sheet_name</span> = <span class="ruby-identifier">sheet</span>.<span class="ruby-identifier">name</span>
    <span class="ruby-identifier">sheet_obj</span>.<span class="ruby-identifier">sheet_id</span> = <span class="ruby-identifier">sheet</span>.<span class="ruby-identifier">sheet_id</span>
    <span class="ruby-identifier">sheet_obj</span>.<span class="ruby-identifier">state</span> = <span class="ruby-identifier">sheet</span>.<span class="ruby-identifier">state</span>
  }

  <span class="ruby-identifier">root</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


    </section>

     <section id="public-instance-5Buntitled-5D-method-details" class="method-section anchor-link">
       <header>
         <h3>Public Instance Methods</h3>
       </header>


      <div id="method-i-related_objects" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-related_objects" title="Link to this method">
                <span class="method-name">related_objects</span>
                <span class="method-args">()</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="related_objects-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/root.rb, line 21</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">related_objects</span>
  [ <span class="ruby-identifier">content_types</span>, <span class="ruby-identifier">thumbnail</span>, <span class="ruby-identifier">core_properties</span>, <span class="ruby-identifier">document_properties</span>, <span class="ruby-identifier">custom_properties</span>, <span class="ruby-identifier">workbook</span> ]
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


      <div id="method-i-stream" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-stream" title="Link to this method">
                <span class="method-name">stream</span>
                <span class="method-args">()</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="stream-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/root.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">stream</span>
  <span class="ruby-identifier">stream</span> = <span class="ruby-constant">Zip</span><span class="ruby-operator">::</span><span class="ruby-constant">OutputStream</span>.<span class="ruby-identifier">write_buffer</span>(<span class="ruby-value">suppress_extra_fields:</span> <span class="ruby-keyword">true</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">zipstream</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">rels_hash</span> = {}
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">relationship_container</span>.<span class="ruby-identifier">owner</span> = <span class="ruby-keyword">self</span>
    <span class="ruby-identifier">collect_related_objects</span>.<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;&lt;-- DEBUG: adding relationship to #{obj.class}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">@@debug</span>
      <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">root</span> = <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:root=</span>)
      <span class="ruby-keyword">self</span>.<span class="ruby-identifier">rels_hash</span>[<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span>] <span class="ruby-operator">||=</span> []
      <span class="ruby-keyword">self</span>.<span class="ruby-identifier">rels_hash</span>[<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">obj</span>
    }

    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">rels_hash</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">sort_by</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span><span class="ruby-operator">::</span><span class="ruby-constant">SAVE_ORDER</span> }.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">klass</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;&lt;-- DEBUG: saving related #{klass} files&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">@@debug</span>
      <span class="ruby-keyword">self</span>.<span class="ruby-identifier">rels_hash</span>[<span class="ruby-identifier">klass</span>].<span class="ruby-identifier">select!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;&lt;-- DEBUG:   &gt; #{obj.xlsx_path}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">@@debug</span>
        <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">add_to_zip</span>(<span class="ruby-identifier">zipstream</span>)
      }
    }
  }
  <span class="ruby-identifier">stream</span>.<span class="ruby-identifier">rewind</span>
  <span class="ruby-identifier">stream</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          <p>Write <code>.xlsx</code> to a stream (useful for sending over HTTP)</p>


        </div>





      </div>


      <div id="method-i-xlsx_path" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-xlsx_path" title="Link to this method">
                <span class="method-name">xlsx_path</span>
                <span class="method-args">()</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="xlsx_path-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/root.rb, line 58</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">xlsx_path</span>
  <span class="ruby-constant">OOXMLTopLevelObject</span><span class="ruby-operator">::</span><span class="ruby-constant">ROOT</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


    </section>

  </section>

</main>
</body>

